package com.order.controller;

import com.alibaba.fastjson.JSONObject;
import com.order.entity.ResOrderStageTemplate;
import com.bhudy.enums.Relation;
import com.sys.utils.RequestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bhudy.base.QueryFilter;
import com.order.service.ResOrderStageTemplateService;

/**
 * @Author 卞洪业
 * @Description ResOrderStageTemplateController
 * @Date Wed Feb 19 17:05:03 CST 2020
 */
@RestController
public class ResOrderStageTemplateController {

    @Autowired
    private ResOrderStageTemplateService resOrderStageTemplateService;

    /**
     * 获取ResOrderStageTemplate表的数据
     *
     * @param page  页数{1}
     * @param limit 显示数量{10}
     * @return ResOrderStageTemplate的list
     */
    @GetMapping(value = "/api/v1/resOrderStageTemplates")
    public Object getAll(Integer page, Integer limit, String resOrderTypeId) {
        QueryFilter queryFilter = new QueryFilter().and("status", Relation.NOT_EQUAL, 1);
        if (page != null && limit != null) queryFilter.limit(--page, limit);
        if (resOrderTypeId != null && !resOrderTypeId.equals("")) queryFilter.and("resOrderTypeId", resOrderTypeId);
        queryFilter.orderASC("resOrderTypeId", "stageSort");
        return RequestUtils.printMapJson(0, resOrderStageTemplateService.count(queryFilter), resOrderStageTemplateService.findList(queryFilter));
    }

    @GetMapping(value = "/api/v1/resOrderStageTemplate")
    public Object get(Long resOrderStageTemplateId) {
        return RequestUtils.printMapJson(0, resOrderStageTemplateService.get(resOrderStageTemplateId));
    }

    /*@PostMapping(value = "/api/v1/resOrderStageTemplate")
    public Object insert(@RequestBody Stringa json) {
        return RequestUtils.printMapJson(0, resOrderStageTemplateService.insert(JSONObject.parseObject(json, ResOrderStageTemplate.class)));
    }*/

    @PutMapping(value = "/api/v1/resOrderStageTemplate")
    public Object update(@RequestBody String json) {
        return RequestUtils.printMapJson(0, resOrderStageTemplateService.update(JSONObject.parseObject(json, ResOrderStageTemplate.class)));
    }

    /*@DeleteMapping(value = "/api/v1/resOrderStageTemplates")
    public Object delete(@RequestBody Stringa json) {
        return RequestUtils.printMapJson(0, resOrderStageTemplateService.delete(JSONObject.parseObject(json, Stringa[].class)));
    }*/

}
